import format from '@dfeidao/atom-web/dt/format';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from "@dfeidao/atom-web/render/render";
import p001 from './p001';
import p002 from './p002';
export default async function a001(fd: IFeidaoAiBrowserComponent, no: string) {
	// todo
	const n = fd.data.node.querySelector<HTMLDivElement>('[data-id="main"]');
	n.setAttribute('class', ' ');

	const res = await nodejs<Array<{}>>('imple-records/zj-000005/s001', {
		no
	});

	render(fd, (res[0])[0], p001, 'p001', 'inner');

	const res2 = await nodejs<Array<{ check_item_no: string, recording_time: string, inside: Array<{}> }>>('imple-records/zj-000005/s002', {
		no
	});


	res2.map((v) => {
		v.recording_time = format(Number(v.recording_time), 0);
		v.inside = [{}];
		v.inside.shift();
	});

	for (let i = 0; i < res2.length; i++) {
		const res3 = await nodejs<Array<{ hidden_name: string; hidden_source_feature_name: string; control_data: string; feature: string, result: string }>>('imple-records/zj-000005/s003', {
			no: res2[i].check_item_no
		});
		res3.map(async (v) => {
			if (!v.hidden_source_feature_name) {
				v.hidden_source_feature_name = '无';
			}
			if (!v.hidden_name) {
				v.hidden_name = '无';
			}
			if (!v.control_data) {
				v.feature = '无';
				v.result = '无';
			}
			if (v.control_data === "定量") {
				const res5 = await nodejs<Array<{ down_value: string, upper_limit: string, unit: string }>>('imple-records/zj-000005/s004', {
					hidden_source_feature_no: "HF20190507000076"
				});
				const mt = res5[0].down_value + " ~ " + res5[0].upper_limit + " " + res5[0].unit;
				v.feature = mt;
			}
			if (v.control_data === "定性") {
				v.feature = '无';
				v.result = '无';
				const res6 = await nodejs<Array<{ qt_hidden_st: string }>>('imple-records/zj-000005/s005', {
					hidden_source_feature_no: "HS000003"
				});
				if (res6[0]) {
					v.feature = res6[0].qt_hidden_st;
				} else {
					v.feature = '无';
				}
			}
		});
		res2[i].inside.push(res3);
	}
	// console.log(res2, 'old');
	render(fd, res2, p002, 'p002', 'inner');

	// const res4 = Array({});
	// res4.shift();
	// for (let i = 0; i < res2.length; i++) {
	// 	const res3 = await nodejs<Array<{ hidden_name: string; hidden_source_feature_name: string; control_data: string; feature: string, result: string }>>('imple-records/zj-000005/s003', {
	// 		no: res2[i].check_item_no
	// 	});
	// 	res3.map(async (v) => {
	// 		if (!v.hidden_source_feature_name) {
	// 			v.hidden_source_feature_name = '无';
	// 		}
	// 		if (!v.hidden_name) {
	// 			v.hidden_name = '无';
	// 		}
	// 		if (!v.control_data) {
	// 			v.feature = '无';
	// 			v.result = '无';
	// 		}
	// 		if (v.control_data === "定量") {
	// 			const res5 = await nodejs<Array<{ down_value: string, upper_limit: string, unit: string }>>('imple-records/zj-000005/s004', {
	// 				hidden_source_feature_no: "HF20190507000076"
	// 			});
	// 			const mt = res5[0].down_value + " ~ " + res5[0].upper_limit + " " + res5[0].unit;
	// 			v.feature = mt;
	// 		}
	// 		if (v.control_data === "定性") {
	// 			v.feature = '无';
	// 			v.result = '无';
	// 			const res6 = await nodejs<Array<{ qt_hidden_st: string }>>('imple-records/zj-000005/s005', {
	// 				hidden_source_feature_no: "HS000003"
	// 			});
	// 			if (res6[0]) {
	// 				v.feature = res6[0].qt_hidden_st;
	// 			} else {
	// 				v.feature = '无';
	// 			}
	// 		}
	// 	});
	// 	res4.push(res3);
	// }
	// console.log(res4, 'now');

	// const res5 = await nodejs<Array<{ down_value: string, upper_limit: string, unit: string }>>('imple-records/zj-000005/s004', {
	// 	hidden_source_feature_no: "HF20190507000076"
	// });
	// const mt = res5[0].down_value + " ~ " + res5[0].upper_limit + " " + res5[0].unit;
	// console.log(res5[0], 'datatest');
	// console.log(mt);

	// const res6 = await nodejs<Array<{ qt_hidden_st: string }>>('imple-records/zj-000005/s005', {
	// 	hidden_source_feature_no: "HS000003"
	// });
	// if (res6[0]) {
	// 	console.log(res6[0].qt_hidden_st);
	// } else {
	// 	console.log(123);

	// }



}

